<template>
  <div>
    <div class="app">
      <label class="label28">
        <span class="span28">请输入</span>
        <input class="inp28" v-model.trim="name" type="text" required />
      </label>
      <b-button class="btn" variant="outline-primary" @click="querys"
        >查询</b-button
      >
    </div>
  </div>
</template>

<script>
import bus from "../../eventBus.js";
export default {
  name: "Search",
  data() {
    return {
      name: "",
      table: "",
      queryResult: null,
    };
  },
  props: ["qinfo"],
  created() {
    this.table = this.qinfo;
  },
  methods: {
    querys() {
      if (this.name.length == 0) return;
      else {
        const table = this.table;
        let name = this.name;
        this.$axios
          .get("http://127.0.0.1/querys", {
            params: {
              name: name,
              table: table,
            },
          })
          .then((res) => {
            this.queryResult = res.data;
            if (table == "scenery") {
              setTimeout(() => {
                bus.$emit("sceneryRes", this.queryResult);
              }, 0);
            } else if (table == "travel") {
              setTimeout(() => {
                bus.$emit("travelRes", this.queryResult);
              }, 0);
            }
            //控制属性面板显示
            bus.$emit("VisibPanel", "True");
            if (this.$route.name != table) {
              this.$router.push(`/${table}`);
            }
          });
      }
    },
  },
};
</script>

<style scoped>
.app {
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  position: relative;
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
}
.label28 {
  width: 190px;
  height: 68px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  cursor: text;
}
.span28 {
  width: 100%;
  color: #000;
  font-size: 14px;
  margin-bottom: 6px;
  padding: 0 10px;
}
.inp28 {
  width: 100%;
  padding: 0 10px;
  height: 2px;
  border: 0;
  font-size: 14px;
  box-sizing: border-box;
  background-color: rgba(0, 0, 0, 0.1);
  transition: 0.3s;
}
.inp28:hover {
  background-color: rgba(50, 133, 255, 0.7);
}
.inp28:focus,
.inp28:valid {
  background-color: rgba(50, 133, 255, 0.2);
  border: 2px solid rgba(50, 133, 255, 0.7);
  border-radius: 4px;
  height: 42px;
  color: #000;
}
.btn {
  margin-bottom: 8px;
  width: 75px;
  height: 42px;
}
</style>